<%@ page language="java" import="java.util.*" import="java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查找结果</title>
</head>
<body>
<table align="center" border="1">
<tr><th colspan="4">查找结果</th>
<th colspan="1"><a href='index.jsp'>返回</a></th></tr>
<tr><th>编号</th><th>书名</th><th>作者</th><th>价格</th><th>操作</th></tr>
<%
request.setCharacterEncoding("utf-8");
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/gp","root","123456");
Statement stmt=con.createStatement();
String name=request.getParameter("name");
String sql="select * from books where name='" + name +"'";
ResultSet rs=stmt.executeQuery(sql);
int flag=0;
while(rs.next()){
	flag=1;
	int id=rs.getInt(1);
	out.println("<tr><td>"+id+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td><td><a href='edit.jsp?id="+id+"'>修改</a>&nbsp;<a href='delete.jsp?id="+id+"'>删除</a></td></tr>");
}
if(flag==1){
	out.println("<script>alert('查找完成！');</script>");
}else{
	out.println("<script>alert('没有找到！');</script>");
	response.setHeader("refresh", "1;url=index.jsp");
}
rs.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>